package com.aoyy.dao;

import java.util.List;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.aoyy.model.User;
/**==========================================================================
 * <code>UserDaoImpl</code> class for <code>User </code> DAO
 * @author Administrator
 * @date 2017-07-13
 * =========================================================================== */
@Repository("userDao")
@Transactional
public class UserDaoImpl extends BaseDaoImpl<User> implements IUserDao {
  @Override
  @Transactional(propagation=Propagation.NOT_SUPPORTED, readOnly=true)
  public User login(User user) {
	if (user != null && user.getUserName() != null && user.getPassword() != null) {
	  String where = "where userName = ? and password = ?";
	  Object[] parameters = {user.getUserName(), user.getPassword()};
	  List<User> list = this.query(where, parameters, -1, -1).getList();
	  if (list != null && list.size() > 0) {
		return list.get(0);  
	  }
	}
	return null;
  }

  @Override
  @Transactional(propagation=Propagation.NOT_SUPPORTED, readOnly=true)
  public Boolean isUniqueUser(User user) {
	if (user != null && user.getUserName() != null) {
	  String hql = "from User where userName = ?";
	  Object[] parameters = {user.getUserName()};
	  if (uniqueResult(hql, parameters) != null) {
		return false;  
	  }
	}
	return true;
  }
  
}
